//
// Copyright (c) 2024 BPer
//

#ifndef INCLUDE_BPERRTC_BPERPEERCONNECTION_H_
#define INCLUDE_BPERRTC_BPERPEERCONNECTION_H_
#include <bperutil/BPerAvInfoType.h>

typedef struct{
	void* conn;
	BPerAVInfo* avinfo;
	BPerStreamConfig streamconfig;
}BPerPeer;

typedef struct {
	BPerPeer peer;
	void (*init)(BPerPeer* peer);

	int32_t (*addAudioTrack)(BPerPeer* peer,BPerAudioCodec codec);
	int32_t (*addVideoTrack)(BPerPeer* peer,BPerVideoCodec codec);

	int32_t (*addTransceiver)(BPerPeer* peer,BPerRtcDirection direction);
	BPerIceCandidateType (*getIceCandidateType)(BPerPeer* peer);

	int32_t (*createOffer)(BPerPeer* peer, char **psdp);
	int32_t (*createAnswer)(BPerPeer* peer,char* answer);
	int32_t (*createHttpAnswer)(BPerPeer* peer,char* answer);
	int32_t (*createDataChannel)(BPerPeer* peer);

	int32_t (*setLocalDescription)(BPerPeer* peer,char* sdp);
	int32_t (*setRemoteDescription)(BPerPeer* peer,char* sdp);
	int32_t (*connectSfuServer)(BPerPeer* peer);//srs zlm
	int32_t (*connectWhipWhepServer)(BPerPeer* peer,char* url);
	int32_t (*close)(BPerPeer* peer);

	BPerBool (*isAlive)(BPerPeer* peer);
	BPerBool (*isConnected)(BPerPeer* peer);
	BPerRtcConnectionState (*getConnectionState)(BPerPeer* peer);

	int32_t (*on_audio)(BPerPeer* peer,BPerFrame* audioFrame);
	int32_t (*on_video)(BPerPeer* peer,BPerFrame* videoFrame);
	int32_t (*on_message)(BPerPeer* peer,BPerFrame* msgFrame);

	int32_t (*sendRtcMessage)(BPerPeer* peer, BPerRtcMessageType mess);
}BPerPeerConnection;


#ifdef __cplusplus
extern "C"{
#endif
void bPer_create_peerConnection(BPerPeerConnection* peerconn);
void bPer_destroy_peerConnection(BPerPeerConnection* peerconn);

int32_t bPer_p2p_getHttpSdp(BPerIpFamilyType familyType,char* httpIp,int32_t httpPort,char* localSdp,char* remoteSdp);
#ifdef __cplusplus
}
#endif
#endif /* INCLUDE_BPERRTC_BPERPEERCONNECTION_H_ */
